package router

import (
	"user_api/api"
	"user_api/middleware"

	"github.com/gin-gonic/gin"
)

func InitApiRouter(r *gin.RouterGroup) {

	userRouter := r.Group("/user")
	{
		// 内部系统，不开放注册，而是默认的admin帐号创建帐号密码，以及权限
		userRouter.POST("/create", middleware.JWTAuth(), middleware.IsAdminAuth(), api.PostCreateUser)
		// 用户登录
		userRouter.POST("/login", api.PostUserLogin)
		// 获取用户列表
		userRouter.GET("/list", middleware.JWTAuth(), middleware.IsAdminAuth(), api.GetUserList)
		// 更新用户的role
		userRouter.PUT("/role", middleware.JWTAuth(), middleware.IsAdminAuth(), api.UpdateUserRole)
		// 更新用户的用户名
		userRouter.PUT("/username", middleware.JWTAuth(), api.UpdateUsername)
		// 删除用户
		userRouter.DELETE("/:username", middleware.JWTAuth(), middleware.IsAdminAuth(), api.DeleteUser)
		// 生成apikey
		userRouter.POST("/apikey", middleware.JWTAuth(), api.CreateApikey)
		// 获取apiKey
		userRouter.GET("/apikey", middleware.JWTAuth(), api.GetApikey)
	}

	baseRouter := r.Group("/base")
	{
		baseRouter.GET("/captcha", api.GetCaptcha)
	}
}
